package com.itheima.dfs;

import com.github.tobato.fastdfs.domain.conn.FdfsWebServer;
import com.itheima.wemedia.pojo.WmMaterial;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.itheima.common.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class DeleteController {
    //注入文件上传删除对象
    @Autowired
    private FastFileStorageClient client;

    /**
     * fds删除文件接口
     * @param wmMaterial 素材对象
     * @return 返回是否删除成功
     */
    @ApiOperation("删除素材接口")
    @PostMapping("/delete")
    ResultVo deleteUrl(@RequestBody WmMaterial wmMaterial){
        String url = wmMaterial.getUrl();
        //根据文件id删除，文件
        client.deleteFile(url);
        return ResultVo.ok("删除素材成功");
    }
}
